layui.config({
	base : "js/"
}).use(['form','layer','jquery','layedit','laydate'],function(){
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		layedit = layui.layedit,
		laydate = layui.laydate,
		$ = layui.jquery;
	
	
	layedit.set({
		  uploadImage: {
		    url: '../admin/uploadActivityImg' //接口url
		    ,type: 'post' //默认post
		  }
	});
	
	//创建一个编辑器
 	var editIndex = layedit.build('news_content');
 	
 	
 	form.on("submit(addNews)",function(data){
	 	//显示状态
 		var isShow = data.field.show=="on" ? "1" : "0";
 		var isRecommend = data.field.tuijian=="on" ? "1" : "0";
 		
 		var id = $("#id").val();
 		if(id==""){
 			id=null;
 		}
 		var title = $(".newsName").val();
 		var isAuth = $(".newsLook").val();
 		var issueTime = $(".newsTime").val();
 		var issueMan = $(".newsAuthor").val();
 		var keyWord = $("#keyWord").val();
 		var head = $("#head").val();
 		//获取内容
 	 	var msg = layedit.getContent(editIndex);
 		//弹出loading
 		var index = layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        setTimeout(function(){
        	$.ajax({
        		url:"/admin/insertActivity",
        		type:"POST",
        		data:{id:id,title:title,isAuth:isAuth,issueTime:issueTime,
        			issueMan:issueMan,isShow:isShow,isRecommend:isRecommend,keyWord:keyWord,head:head,msg:msg},
        		success:function(data){
        			if(data.rspCode=="000000"){
        				layer.close(index);
        				layer.msg("活动添加成功！");
        	 			layer.closeAll("iframe");
        		 		//刷新父页面
        		 		parent.location.reload();
        			}else{
            			layer.msg("活动添加失败！");
        			}
        		},
        		error:function(data){
        			console.log("活动添加出错！");
        		}
        	});
        },0);
 		return false;
 	})
	
})
